from python_baway.common.xcommon import sep

sep('read x_try_open.py')
f = open('x_try_open.py', encoding='utf-8')
print(f.read())
f.close()

sep('read ../function_recursive/Hanoi.py')
f2 = open('../function_recursive/Hanoi.py', encoding='UTF8')
print(f2.read())
f2.close()

sep('w to test.tmp.txt')
f3 = open('test.tmp.txt', 'w', encoding='utf8')
xord = ord('我')
n = 0
for x in range(xord, xord+20):
    f3.write(chr(x))
    if n % 10 == 9:
        f3.write('\n')
    n += 1
f3.close()

sep('ab to test.tmp.txt')
f4 = open('test.tmp.txt', 'ab')
xord = ord('我')
n = 0
for x in range(xord, xord+20):
    f4.write(chr(x).encode(encoding='utf8'))
    if n % 10 == 9:
        f4.write('\n'.encode(encoding='utf8'))
    n += 1
f4.close()

sep('rb test.tmp.txt')
f5 = open('test.tmp.txt', 'rb')
print(f5.read().decode(encoding='utf8'))
f5.close()
